#include "pawn.h"
#include <QList>

Pawn::Pawn(Cell *cell, QString color, QWidget *parent): Piece(cell, color, parent){
    loadPieceImage(color + "pawn");
    cell->setPiece(this);
}

QList<Cell *> Pawn::getTips(Board *board)
{
    QList<Cell *> tips;
    if (this->getColor() == "W"){
        int l = getCell()->getY()==2?2:1;
        for (int i = 1; i <= l; i++){
            Cell *c = isMove(0, i, board);
            if (c == nullptr){
                break;
            }else{
                if (c->hasPiece())
                    break;
                tips << c;
            }
        }
        Cell *c = isMove(1, 1, board);
        if (c != nullptr && c->hasPiece()){
            tips << c;
        }
        c = isMove(-1, 1, board);
        if (c != nullptr && c->hasPiece()){
            tips << c;
        }
    }else{
        int l = getCell()->getY()==7?2:1;
        for (int i = 1; i <= l; i++){
            Cell *c = isMove(0, -i, board);
            if (c == nullptr){
                break;
            }else{
                if (c->hasPiece())
                    break;
                tips << c;
            }
        }
        Cell *c = isMove(1, -1, board);
        if (c != nullptr && c->hasPiece()){
            tips << c;
        }
        c = isMove(-1, -1, board);
        if (c != nullptr && c->hasPiece()){
            tips << c;
        }
    }
    return tips;
}
